<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
    我们可以用变量保存当前最大的值max，当nums[i]小于leftmax时，更新splitIdx = i， leftmax = max
    */
    var partitionDisjoint = function (nums) {
      const n = nums.length;
      let splitIdx = 0;
      let leftmax = nums[0];
      let max = 0;
      for (let i = 1; i < n; i++) {
        if (nums[i] < leftmax) {
          splitIdx = i;
          leftmax = max;
        } else if (nums[i] > max) {
          max = nums[i];
        }
      }
      return splitIdx + 1;
    };
    console.log(partitionDisjoint([1, 1, 1, 0, 6, 12]))
  </script>
</body>

</html>